-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: split input output note register structs #199
Conversation
…ragaBA-split-input-notes-table
…ragaBA-split-input-notes-table
…ragaBA-split-input-notes-table
…ragaBA-split-input-notes-table
This reverts commit bf46c0a.
…ragaBA-split-input-notes-table
…ragaBA-split-input-notes-table
…ragaBA-split-input-notes-table
…ragaBA-split-input-notes-table
I still have pending polishing the changes (abstracting some deserialization and removing debugs, etc.) and we should also add some kind of validation as well as having the proper NULL / NOT NULL columns (now everything is nullable)
…ragaBA-split-input-notes-table
…onMiden/miden-client into mFragaBA-serialize-fields-as-json
There were two different kind of errors: * When we queried for less fields than what parse_input_notes_columns expected (this happened on the function to get peding input note nullifiers) * When we serialized the note status. Apparently serde serializes the note as `\"Variant\"` instead of `variant`.
…ragaBA-serialize-fields-as-json
…gonMiden/miden-client into mFragaBA-split-input-output-note-structs
…ragaBA-serialize-fields-as-json
…gonMiden/miden-client into mFragaBA-split-input-output-note-structs
…ragaBA-serialize-fields-as-json
…gonMiden/miden-client into mFragaBA-split-input-output-note-structs
…ragaBA-split-input-output-note-structs
9626b2f
to
b5574b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I left a couple of comments and questions. I think with the differentiation now of how input notes and output notes are treated, we might want to make sure we have tests covering the new code.
src/store/mod.rs
Outdated
match value { | ||
0 => NoteStatus::Pending, | ||
1 => NoteStatus::Committed, | ||
_ => NoteStatus::Consumed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be a TryFrom
implementation? I think it's worth it to match only for 2
here, and error out if it's something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I used the existing DeserializationError
for its error type
src/store/mod.rs
Outdated
inclusion_proof: Option<NoteInclusionProof>, | ||
metadata: Option<NoteMetadata>, | ||
recipient: Digest, | ||
status: NoteStatus, | ||
} | ||
|
||
impl InputNoteRecord { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these structs are getting large with the impl blocks, should we move them to their own files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change made on 21fc72e
src/store/mod.rs
Outdated
); | ||
Ok(InputNote::new(note, proof.clone())) | ||
} | ||
// TODO: should we use a better Error for these two? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these errors look OK. An alternative could be to make it a specific variant for ClientError
, since the problem might be indicate that the client has not synced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the message within the string is OK, but the error variant InvalidOriginIndex
is what seems off to me. But perhaps for now it's enough
let note_metadata: Option<NoteMetadata> = if let Some(metadata_as_json_str) = note_metadata { | ||
Some( | ||
serde_json::from_str(&metadata_as_json_str) | ||
.map_err(StoreError::JsonDataDeserializationError)?, | ||
) | ||
} else { | ||
None | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be written a little bit more succinctly like this:
let note_metadata: Option<NoteMetadata> = note_metadata.map(serde_json::from_str...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that at first but the problem is that I wouldn't be able to use the ?
to propagate the error
src/store/sqlite_store/notes.rs
Outdated
// FIXME: This removal is to accomodate a problem with how the node constructs paths where | ||
// they are constructed using note ID instead of authentication hash, so for now we remove the first | ||
// node here. | ||
// | ||
// Note: once removed we can also stop creating a new `NoteInclusionProof` | ||
// | ||
// See: https://github.com/0xPolygonMiden/miden-node/blob/main/store/src/state.rs#L274 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bobbinth we have been dragging this FIXME for a while now, is this getting tracked somewhere? I recall it being mentioned a couple of times but I just quickly searched for it in related issues and did not find anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is supposed to be a part of 0xPolygonMiden/miden-base#464 - but I haven't been able to finish it yet.
…ragaBA-split-input-output-note-structs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
* split input notes * make enum for notes tables * rename recipients variable and add more NoteTable uses * run fmt * change to_string for to_hex * correct nullable fields and reorder fields * remove unnecesarry note filter * remove unnecessary commit_height field * move related rows into metadata row for notes * remove dbg statements * switch to_string for to_hex * Revert "move related rows into metadata row for notes" This reverts commit bf46c0a. * restore filtering by pending notes * store grouped json fields * add json fields with serialization/deserialization I still have pending polishing the changes (abstracting some deserialization and removing debugs, etc.) and we should also add some kind of validation as well as having the proper NULL / NOT NULL columns (now everything is nullable) * remove dbg calls and set nullable/non-nullable cols accordingly * apply clippy suggestion * add helper functions to work with json values returned as strings * add documentation for handling json with sqlite * fix incorrect function use to fetch output notes * ignore doc tests * add json validity constraints * use structs to represent json columns * remove dbg statements * use propper serialization * use existing NoteMetadata instead of NoteRecordMetadata * also remove NoteRecordInclusionProof and use NoteInclusionProof instead * add implementations for output notes * change input note record struct TODO: fix tests * Fix test failures There were two different kind of errors: * When we queried for less fields than what parse_input_notes_columns expected (this happened on the function to get peding input note nullifiers) * When we serialized the note status. Apparently serde serializes the note as `\"Variant\"` instead of `variant`. * update doc comments * cleanup struct * remove dbg statements * fix serialization for output notes * change from to tryfrom for notestatus * move note record structs to its own module * remove todo comment * remove quotes from note status
addresses #197. This PR achieves 2 things:
I suggest checking this PR in 3 steps:
sqlite_store/notes.rs
,store/mod.rs
,store/store.sql
XNoteRecord
Summary of changes
InputNoteRecord
intoInputNoteRecord
andOutputNoteRecord
structs. While they store similar fields, they support slightly different fields and as discussed on Split/RefactorNoteRecord
related logic to handle possible flows #197, this approach would be more flexible to refactor in the future. As a consecuence, we now have separate:SerializedInputNoteData
andSerializedOutputNoteData
SerializedInputNoteParts
andSerializedOutputNoteParts
parse_input_note_columns
andparse_output_columns
functionsparse_input_note
andparse_output_note
functionsserialize_input_note
andserialize_output_note
functionsXNoteRecord
structs, we replace theNote
with its fields as some of them might not be known depending on the flow. As a consecuence:String
orVec<u8>
since the actual type does not implement serde'sSerialize
andDeserialize
traits. We added the necessary casting. It should be discussed whether we want the interface of the struct to return theseString
orVec
or we want to return the proper types (perhaps we can keep it as is but addFrom
implementations).serialize_X_note
,parse_X_note_column
andparse_X_note
functions are now slightly different since we need to adjust to the new note record fieldsInputNoteRecord
in the client and the cli had to be accordingly updatedNoteStatus
. While it's quite declarative, i don't like that some queries now do for exampleINSERT ... status = '"Committed"' ...
though to account for serde's way of serializing the enum as a json string. Any suggestions are more than welcome